/*
 * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.dreamlu.common.thymeleaf;

import net.dreamlu.common.thymeleaf.processor.SelectElementTagProcessor;
import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;

import java.util.HashSet;
import java.util.Set;

/**
 * 字典 处理
 *
 * @author L.cm
 */
@Component
public class SysDictProcessorDialect extends AbstractProcessorDialect {
	/**
	 * tab 名
	 */
	private static final String DIALECT_NAME = "Dict Dialect";
	/**
	 * 前缀
	 */
	private static final String DIALECT_PREFIX = "x";
	private static final int PRECEDENCE = 1000;
	/**
	 * 字典服务
	 */
	private final SysDictFunc dictFunc;

	public SysDictProcessorDialect(SysDictFunc dictFunc) {
		super(DIALECT_NAME, DIALECT_PREFIX, PRECEDENCE);
		this.dictFunc = dictFunc;
	}

	@Override
	public Set<IProcessor> getProcessors(final String dialectPrefix) {
		final Set<IProcessor> processors = new HashSet<>(1);
		processors.add(new SelectElementTagProcessor(dialectPrefix, PRECEDENCE, dictFunc));
		return processors;
	}
}
